package com.hinacom.pix.web.controller;

import ca.uhn.hl7v2.HL7Exception;
import com.hinacom.pix.client.BaseClient;
import com.hinacom.pix.client.PDQConsumer;
import com.hinacom.pix.client.PIXConsumer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by fyu on 2016/9/5.
 */
@Controller
@RequestMapping("general-test")
public class GeneralTestController {

    @RequestMapping("")
    public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
        ModelAndView mv = new ModelAndView("general-test");
        return mv;
    }

    @RequestMapping("/send")
    public ModelAndView generalTestSubmit(String actor, String message) throws HL7Exception {
        BaseClient client = null;

        if (actor.equalsIgnoreCase("PIX")) {
            client = new PIXConsumer();
        } else {
            client = new PDQConsumer();
        }

        String result = client.sendMessage(message);
        result = result.replace("\r","<br/>");
        ModelAndView mv = new ModelAndView("general-test");
        mv.addObject("result", result);
        return mv;
    }
}
